package com.itheima.arraylist;

import com.itheima.domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

public class Test03 {
    public static void main(String[] args) {
        //创建集合对象 泛型为Student
        ArrayList<Student> list = new ArrayList<>();

        //录入键盘信息
        Scanner sc = new Scanner(System.in);
        //录入三次
        for (int i = 0; i < 3; i++) {
            //键盘录入学生姓名和年龄
            System.out.println("录入姓名:");
            String name = sc.next();
            System.out.println("录入年龄:");
            int age = sc.nextInt();
            //根据键盘录入创建学生对象
            Student student = new Student(name, age);
            //list集合添加学生对象
            list.add(student);
        }
        //遍历list集合
        for (int i = 0; i < list.size(); i++) {
            //list.get(i)
            //获取每次遍历的学生对象,并输出
            Student student = list.get(i);
            System.out.println(student);
        }
    }
}
